import os
import multiprocessing


def worker1():
    # 打印进程ID
    print("ID of process running worker1: {}".format(os.getpid()))


def worker2():
    # 打印进程ID
    print("ID of process running worker2: {}".format(os.getpid()))


if __name__ == "__main__":
    # 打印主程序ID
    print("ID of main process: {}".format(os.getpid()))

    # 创建进程
    p1 = multiprocessing.Process(target=worker1)
    p2 = multiprocessing.Process(target=worker2)

    # 启动进程
    p1.start()
    p2.start()

    # 打印进程ID
    print("ID of process p1: {}".format(p1.pid))
    print("ID of process p2: {}".format(p2.pid))

    # 等待两个进程执行完成
    p1.join()
    p2.join()

    print("Both processes finished execution!")

    # 检查两个进程是否还存活
    print("Process p1 is alive: {}".format(p1.is_alive()))
    print("Process p2 is alive: {}".format(p2.is_alive()))
